<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" style="height: 100%">
<head>
    <title>后台管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/nodeModules/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/nodeModules/bootstrap/dist/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="/nodeModules/css/community.css">
    <script src="/nodeModules/jquery/dist/jquery.min.js"></script>
    <script src="/nodeModules/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="/nodeModules/js/community.js"></script>
</head>
<body>
<!--顶部-->
<div th:fragment="nav" class="admin-nav">
    <nav class="navbar navbar-default">
        <div class=" navigation-nav">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                        data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">后台管理系统</span>
                </button>
                <a class="navbar-brand" href="/admin/users">后台管理系统</a>
            </div>
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a id="time" style="margin-right: 30px;color: #666666;font-size: 14px;font-weight: bold"></a>
                    </li>

                    <li th:if="${session.user != null}">
                        <a href="/publish">提问</a>
                    </li>
                    <li><a href="/profile/replies">消息 <span class="badge navigation-message"
                                                            th:if="${session.unreadCount}!=0"
                                                            th:text="${session.unreadCount}"></span></a>
                    </li>
                    <!--collapse 我的-->
                    <li class="dropdown" th:if="${session.user != null}">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                           aria-expanded="false">
                            <img th:src="${session.user.getAvatarUrl()}" class="navigation-avatarUrl img-rounded">
                            <span th:text="${session.user.getName()}"></span>
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a class="glyphicon glyphicon-home" href="/profile/questions"> 我的主页</a></li>
                            <li><a class="glyphicon glyphicon-off" href="/logout"> 退出</a></li>
                        </ul>
                    </li>
                    <!--前台首页-->
                    <li>
                        <a href="/">前台首页</a>
                    </li>
                    <li th:if="${session.user == null}">
                        <!--                        <a th:href="@{https://github.com/login/oauth/authorize(client_id='d0d3ade7e00a78d3000f',redirect_uri=${#httpServletRequest.getServletContext().getAttribute('redirectUri')},scope='user',state=1)}">登录</a>-->
                        <a th:href="@{https://github.com/login/oauth/authorize(client_id='d0d3ade7e00a78d3000f',redirect_uri=${#httpServletRequest.getRequestURL()+'callback'},scope='user',state=1)}">登录</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</div>


<!--内容-->
<div class="container-fluid" style="background-color: #f6f6f6;padding: 0;height: 100%">
    <div class="row" style="height: 100%">
        <!--左侧标签-->
        <div class="col-lg-2 col-md-2 col-sm-3 col-xs-3 "
             style="border-right: 2px solid #666666;height: 100%;background-color: white">
            <div style="height: 130px;width: 100%">
                <img th:src="${session.user.getAvatarUrl()}" class="admin-img img-circle">
                <p style="text-align: center;font-size: 12px;font-weight: bold">
                    你好！<span th:text="${session.user.getName()}"></span>, 欢迎回来
                </p>
            </div>
            <div class="admin-leftside-tab">
                <ul class="list-group section">
                    <li style="position: relative;left: 3%;text-align: center;"
                        th:classappend="${section == 'users'} ? ' disabled list-group-item' : 'list-group-item' ">
                        <a href="/admin/users">
                            <i class="glyphicon glyphicon-user"></i>
                            <cite>用户管理</cite>
                            <span class="caret" style="margin-left: 25%;"></span>
                        </a>
                    </li>
                    <li style="position: relative;left: 3%;text-align: center"
                        th:classappend="${section == 'questions'} ? 'disabled list-group-item' : 'list-group-item' ">
                        <a href="/admin/questions">
                            <i class="glyphicon glyphicon-book"></i>
                            <cite>帖子管理</cite>
                            <span class="caret" style="margin-left: 25%;"></span>
                        </a>
                    </li>
                    <li style="position: relative;left: 3%;text-align: center"
                        th:classappend="${section == 'comments'} ? 'disabled list-group-item' : 'list-group-item' ">
                        <a href="/admin/comments">
                            <i class="glyphicon glyphicon-comment"></i>
                            <cite>评论管理</cite>
                            <span class="caret" style="margin-left: 25%;"></span>
                        </a>
                    </li>
                    <li style="position: relative;left: 3%;text-align: center"
                        th:classappend="${section == 'notification'} ? 'disabled list-group-item' : 'list-group-item' ">
                        <a href="/admin/notification">
                            <i class="glyphicon glyphicon-send"></i>
                            <cite>通知管理</cite>
                            <span class="caret" style="margin-left: 25%;"></span>
                        </a>
                    </li>
                </ul>
            </div>
        </div>

        <!--右侧内容-->
        <div class="col-lg-10 col-md-10 col-sm-9 col-xs-9">
            <div class="tab-content">
                <!--用户管理-->
                <div th:if="${section=='users'}">
                    <div class="col-xs-12 col-sm-12 col-md-12 col-xs-12">
                        <!--搜索查询用户-->
                        <form class="navbar-form navbar-left" action="/admin/users" method="get">
                            <div class="form-group input-group">
                                <input type="text" class="form-control" name="search" placeholder="查询用户名">
                                <span class="input-group-btn">
                            <button class="btn btn-default " type="submit">搜索</button>
                        </span>
                            </div>
                            <!--                    <button type="submit" class="btn btn-default">搜索</button>-->
                        </form>
                        <table class="table table-bordered">
                            <thead>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>Token</th>
                            <th>加入时间</th>
                            <th>登录时间</th>
                            <th>头像</th>
                            <th>操作</th>
                            </thead>
                            <tbody>
                            <tr th:each="user1 : ${paginationUser.data}">
                                <th th:text="${user1.id}"></th>
                                <td th:text="${user1.name}"></td>
                                <td th:text="${user1.token}">
                                    <button type="button" class="btn btn-default" data-toggle="tooltip"
                                            data-placement="right" title="Tooltip on right">Tooltip on right
                                    </button>
                                </td>
                                <td th:text="${#dates.format(user1.gmtCreate,'yyyy-MM-dd HH:mm')}"></td>
                                <td th:text="${#dates.format(user1.gmtModified,'yyyy-MM-dd HH:mm')}"></td>
                                <td>
                                    <img th:src="${user1.avatarUrl}" class="media-object img-rounded">
                                </td>
                                <td>
                                    <!-- 删除模态框按钮 -->
                                    <a class="btn btn-danger btn-sm admin-btn-operation" style="background: red"
                                       data-toggle="modal"  th:onclick="'deleteUser(' + ${user1.id} + ');'"
                                       data-target="#userModel">
                                        删除
                                    </a>

                                    <!-- 删除模态框 -->
                                    <div class="admin-delete-modal modal fade" id="userModel" tabindex="-1" role="dialog"
                                         aria-labelledby="myModalLabel">
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <!--分页-->
                        <nav aria-label="Page navigation">
                            <ul class="pagination">
                                <!--第一页-->
                                <li th:if="${paginationUser.showFirstPage}">
                                    <a th:href="@{'/admin/'+${section}(page=1,search=${search})}" aria-label="Previous">
                                        <span aria-hidden="true">&lt;&lt;</span>
                                    </a>
                                </li>
                                <!--上一页-->
                                <li th:if="${paginationUser.showPrevious}">
                                    <a th:href="@{'/admin/'+${section}(page=${paginationUser.page -1},search=${search})}"
                                       aria-label="Previous">
                                        <span aria-hidden="true">&lt;</span>
                                    </a>
                                </li>
                                <!--当前页-->
                                <li th:each="page : ${paginationUser.pages}"
                                    th:class="${paginationUser.page == page} ? 'active' : '' ">
                                    <a th:href="@{'/admin/'+${section}(page=${page},search=${search})}"
                                       th:text="${page}"></a>
                                </li>
                                <!--下一页-->
                                <li th:if="${paginationUser.showNext}">
                                    <a th:href="@{'/admin/'+${section}(page=${paginationUser.page +1},search=${search})}"
                                       aria-label="Next">
                                        <span aria-hidden="true">&gt;</span>
                                    </a>
                                </li>
                                <!--最后一页-->
                                <li th:if="${paginationUser.showEndPage}">
                                    <a th:href="@{'/admin/'+${section}(page=${paginationUser.totalPage},search=${search})}"
                                       aria-label="Next">
                                        <span aria-hidden="true">&gt;&gt;</span>
                                    </a>
                                </li>
                            </ul>
                        </nav>
                    </div>
                </div>
                <!--帖子管理-->
                <div th:if="${section == 'questions'}">
                    <div class="col-xs-12 col-sm-12 col-md-12 col-xs-12">
                        <!--搜索查询-->
                        <form class="navbar-form navbar-left" action="/admin/questions" method="get">
                            <div class="form-group input-group">
                                <input type="text" class="form-control" name="search" placeholder="查询问题">
                                <span class="input-group-btn">
                            <button class="btn btn-default " type="submit">搜索</button>
                        </span>
                            </div>
                            <!--                    <button type="submit" class="btn btn-default">搜索</button>-->
                        </form>
                        <table class="table table-bordered">
                            <thead>
                            <th>ID</th>
                            <th>创建者</th>
                            <th>标题</th>
                            <th>发布时间</th>
                            <th>浏览次数</th>
                            <th>标签</th>
                            <th>操作</th>
                            </thead>
                            <tbody>
                            <tr th:each="question : ${pagination.data}">
                                <th th:text="${question.id}"></th>
                                <td th:text="${question.creator}"></td>
                                <td th:text="${question.title}"></td>
                                <td th:text="${#dates.format(question.gmtCreate,'yyyy-MM-dd HH:mm')}"></td>

                                <td th:text="${question.viewCount}"></td>
                                <td th:text="${question.tag}"></td>
                                <td>
                                    <a class="btn btn-default btn-sm admin-btn-operation"
                                       th:href="@{'/publish/'+${question.id}}" role="button">编辑</a>
                                    <a class="btn btn-default btn-sm admin-btn-operation"
                                       th:href="@{'/question/'+${question.id}}" role="button">链接</a>
                                    <!-- 删除模态框按钮 -->
                                    <a class="btn btn-danger btn-sm admin-btn-operation" style="background: red" id="question_id"
                                       data-toggle="modal" th:onclick="'deleteQuestion(' + ${question.id} + ');'"
                                       data-target="#questionModal" >
                                        删除
                                    </a>

                                    <!-- 删除模态框 -->
                                    <div class="admin-delete-modal modal fade" id="questionModal" tabindex="-1" role="dialog"
                                         aria-labelledby="myModalLabel">
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <!--分页-->
                        <nav aria-label="Page navigation">
                            <ul class="pagination">
                                <!--第一页-->
                                <li th:if="${pagination.showFirstPage}">
                                    <a th:href="@{'/admin/'+${section}(page=1,search=${search})}" aria-label="Previous">
                                        <span aria-hidden="true">&lt;&lt;</span>
                                    </a>
                                </li>
                                <!--上一页-->
                                <li th:if="${pagination.showPrevious}">
                                    <a th:href="@{'/admin/'+${section}(page=${pagination.page -1},search=${search})}"
                                       aria-label="Previous">
                                        <span aria-hidden="true">&lt;</span>
                                    </a>
                                </li>
                                <!--当前页-->
                                <li th:each="page : ${pagination.pages}"
                                    th:class="${pagination.page == page} ? 'active' : '' ">
                                    <a th:href="@{'/admin/'+${section}(page=${page},search=${search})}"
                                       th:text="${page}"></a>
                                </li>
                                <!--下一页-->
                                <li th:if="${pagination.showNext}">
                                    <a th:href="@{'/admin/'+${section}(page=${pagination.page +1},search=${search})}"
                                       aria-label="Next">
                                        <span aria-hidden="true">&gt;</span>
                                    </a>
                                </li>
                                <!--最后一页-->
                                <li th:if="${pagination.showEndPage}">
                                    <a th:href="@{'/admin/'+${section}(page=${pagination.totalPage},search=${search})}"
                                       aria-label="Next">
                                        <span aria-hidden="true">&gt;&gt;</span>
                                    </a>
                                </li>
                            </ul>
                        </nav>
                    </div>
                </div>
                <!--评论管理-->
                <div th:if="${section == 'comments'}">
                    <div class="col-xs-12 col-sm-12 col-md-12 col-xs-12">
                        <!--搜索查询用户-->
                        <form class="navbar-form navbar-left" action="/admin/comments" method="get">
                            <div class="form-group input-group">
                                <input type="text" class="form-control" name="search" placeholder="查询用户Id">
                                <span class="input-group-btn">
                            <button class="btn btn-default " type="submit">搜索</button>
                        </span>
                            </div>
                            <!--                    <button type="submit" class="btn btn-default">搜索</button>-->
                        </form>
                        <table class="table table-bordered">
                            <thead>
                            <th>ID</th>
                            <th>父ID</th>
                            <th>一级/二级评论</th>
                            <th>评论人</th>
                            <th>评论时间</th>
                            <th style="width: 15%;">评论内容</th>
                            <th>该评论的二级评论数</th>
                            <th>操作</th>
                            </thead>
                            <tbody>
                            <tr th:each="comment : ${paginationComment.data}">
                                <th th:text="${comment.id}"></th>
                                <th th:text="${comment.parentId}"></th>
                                <th th:text="${comment.type}"></th>
                                <th th:text="${comment.commentator}"></th>
                                <th th:text="${#dates.format(comment.gmtCreate,'yyyy-MM-dd HH:mm')}"></th>
                                <th th:text="${comment.content}" style="width: 50px"></th>
                                <th th:text="${comment.commentCount}"></th>
                                <th>
                                    <a class="btn btn-default btn-sm admin-btn-operation"
                                       th:href="@{'/question/'+${comment.parentId}}" role="button">链接</a>
                                    <!-- 删除模态框按钮 -->
                                    <a class="btn btn-danger btn-sm admin-btn-operation" style="background: red"
                                       data-toggle="modal" th:onclick="'deleteComment(' + ${comment.id} + ');'"
                                       data-target="#commentModel">
                                        删除
                                    </a>
                                    <!-- 删除模态框 -->
                                    <div class="admin-delete-modal modal fade" id="commentModel" tabindex="-1" role="dialog"
                                         aria-labelledby="myModalLabel" >
                                    </div>
                                </th>
                            </tr>
                            </tbody>
                        </table>
                        <!--分页-->
                        <nav aria-label="Page navigation">
                            <ul class="pagination">
                                <!--第一页-->
                                <li th:if="${paginationComment.showFirstPage}">
                                    <a th:href="@{'/admin/'+${section}(page=1,search=${search})}" aria-label="Previous">
                                        <span aria-hidden="true">&lt;&lt;</span>
                                    </a>
                                </li>
                                <!--上一页-->
                                <li th:if="${paginationComment.showPrevious}">
                                    <a th:href="@{'/admin/'+${section}(page=${paginationComment.page -1},search=${search})}"
                                       aria-label="Previous">
                                        <span aria-hidden="true">&lt;</span>
                                    </a>
                                </li>
                                <!--当前页-->
                                <li th:each="page : ${paginationComment.pages}"
                                    th:class="${paginationComment.page == page} ? 'active' : '' ">
                                    <a th:href="@{'/admin/'+${section}(page=${page},search=${search})}"
                                       th:text="${page}"></a>
                                </li>
                                <!--下一页-->
                                <li th:if="${paginationComment.showNext}">
                                    <a th:href="@{'/admin/'+${section}(page=${paginationComment.page +1},search=${search})}"
                                       aria-label="Next">
                                        <span aria-hidden="true">&gt;</span>
                                    </a>
                                </li>
                                <!--最后一页-->
                                <li th:if="${paginationComment.showEndPage}">
                                    <a th:href="@{'/admin/'+${section}(page=${paginationComment.totalPage},search=${search})}"
                                       aria-label="Next">
                                        <span aria-hidden="true">&gt;&gt;</span>
                                    </a>
                                </li>
                            </ul>
                        </nav>
                    </div>
                </div>
                <!--通知管理-->
                <div th:if="${section=='notification'}">
                    <div class="col-xs-12 col-sm-12 col-md-12 col-xs-12">
                        <!--搜索同志人-->
                        <form class="navbar-form navbar-left" action="/admin/notification" method="get">
                            <div class="form-group input-group">
                                <input type="text" class="form-control" name="search" placeholder="查询通知人">
                                <span class="input-group-btn">
                            <button class="btn btn-default " type="submit">搜索</button>
                        </span>
                            </div>
                            <!--                    <button type="submit" class="btn btn-default">搜索</button>-->
                        </form>
                        <table class="table table-bordered">
                            <thead>
                            <th>ID</th>
                            <th>通知人ID</th>
                            <th>通知人</th>
                            <th>通知帖子ID</th>
                            <th>通知帖子标题</th>
                            <th>通知是否已经被查看</th>
                            <th>通知时间</th>
                            <th>通知一级/二级评论</th>
                            <th>操作</th>
                            </thead>
                            <tbody>
                            <tr th:each="notification : ${paginationNotification.data}">
                                <th th:text="${notification.id}"></th>
                                <th th:text="${notification.notifier}"></th>
                                <th th:text="${notification.notifierName}"></th>
                                <th th:text="${notification.outerid}"></th>
                                <th th:text="${notification.outerTitle}"></th>
                                <th>
                                    <span th:if="${notification.status}!=0">是</span>
                                    <span th:if="${notification.status}==0">否</span>
                                </th>
                                <th th:text="${#dates.format(notification.gmtCreate,'yyyy-MM-dd HH:mm')}"></th>
                                <th th:text="${notification.type}"></th>
                                <th>
                                    <a class="btn btn-default btn-sm admin-btn-operation"
                                       th:href="@{'/notification/'+${notification.id}}" role="button">链接</a>
                                    <a class="btn btn-danger btn-sm admin-btn-operation" style="background: red"
                                       data-toggle="modal"  th:onclick="'deleteNotification(' + ${notification.id} + ');'"
                                       data-target="#notificationModel">
                                        删除
                                    </a>
                                    <!-- 删除模态框 -->
                                    <div class="admin-delete-modal modal fade" id="notificationModel" tabindex="-1" role="dialog"
                                         aria-labelledby="myModalLabel">
                                    </div>
                                </th>
                            </tr>
                            </tbody>
                        </table>
                        <!--分页-->
                        <nav aria-label="Page navigation">
                            <ul class="pagination">
                                <!--第一页-->
                                <li th:if="${paginationNotification.showFirstPage}">
                                    <a th:href="@{'/admin/'+${section}(page=1,search=${search})}" aria-label="Previous">
                                        <span aria-hidden="true">&lt;&lt;</span>
                                    </a>
                                </li>
                                <!--上一页-->
                                <li th:if="${paginationNotification.showPrevious}">
                                    <a th:href="@{'/admin/'+${section}(page=${paginationNotification.page -1},search=${search})}"
                                       aria-label="Previous">
                                        <span aria-hidden="true">&lt;</span>
                                    </a>
                                </li>
                                <!--当前页-->
                                <li th:each="page : ${paginationNotification.pages}"
                                    th:class="${paginationNotification.page == page} ? 'active' : '' ">
                                    <a th:href="@{'/admin/'+${section}(page=${page},search=${search})}"
                                       th:text="${page}"></a>
                                </li>
                                <!--下一页-->
                                <li th:if="${paginationNotification.showNext}">
                                    <a th:href="@{'/admin/'+${section}(page=${paginationNotification.page +1},search=${search})}"
                                       aria-label="Next">
                                        <span aria-hidden="true">&gt;</span>
                                    </a>
                                </li>
                                <!--最后一页-->
                                <li th:if="${paginationNotification.showEndPage}">
                                    <a th:href="@{'/admin/'+${section}(page=${paginationNotification.totalPage},search=${search})}"
                                       aria-label="Next">
                                        <span aria-hidden="true">&gt;&gt;</span>
                                    </a>
                                </li>
                            </ul>
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    //顶部时间
    function getTime() {
        var myDate = new Date();
        var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
        var myMonth = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
        var myToday = myDate.getDate(); //获取当前日(1-31)
        var myDay = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
        var myHour = myDate.getHours(); //获取当前小时数(0-23)
        var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
        var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
        var week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
        var nowTime;

        nowTime = myYear + '-' + fillZero(myMonth) + '-' + fillZero(myToday) + '&nbsp;&nbsp;' + fillZero(myHour) + ':' + fillZero(myMinute) + ':' + fillZero(mySecond) + '&nbsp;&nbsp;' + week[myDay] + '&nbsp;&nbsp;';
        //console.log(nowTime);
        $('#time').html(nowTime);
    };

    function fillZero(str) {
        var realNum;
        if (str < 10) {
            realNum = '0' + str;
        } else {
            realNum = str;
        }
        return realNum;
    }

    setInterval(getTime, 1000);
</script>
</html>